package com.example.config;

import com.example.domain.Student;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

/**
 * <h3>springboot_redis</h3>
 * <p></p>
 *
 * @author : 你的名字
 * @date : 2020-05-04 17:59
 **/
@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<Object, Object> myRedisTemplate(
            RedisConnectionFactory redisConnectionFactory
    ) {
        RedisTemplate<Object, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);
        Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<Student>(Student.class);
        template.setDefaultSerializer(serializer);
        return template;
    }
}
